package com.speed.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import com.speed.entity.Activiter;
import com.speed.service.ActiviterService;
import com.speed.util.SmsFactory;

/**
 * 短信平台接口
 * @author ZhouChiJian
 *
 */
public class SmsController extends Controller {

	/**
	 * 这里将做成AJAX调用
	 */
	public void index(){
//		//暂时只根据手机号发送
//		String mobile = getPara(0);
//		//这里填写发送的url地址
//		String smsHttp = "http://qc.sms.com/sms";
//		SmsFactory.INSTANCE.send(mobile,"");
//		JSONObject json = new JSONObject();
//		json.put("msg", "短信已经发送成功!");
//		renderJson(json.toJSONString());
		renderJsp("send.jsp");
	}
	
	public void send(){
		String[] mobiles = getParaValues("mobile");
		System.out.println(Arrays.toString(mobiles));
		ActiviterService activiterService = enhance(ActiviterService.class);
		SmsFactory sms = SmsFactory.INSTANCE;
		for(String mp : mobiles){
			Map<String, Object> params = new HashMap<String, Object>();
			params.put(Activiter.ACTIVITER_MOBILE, mp);
			Activiter activiter = activiterService.findActiviterByCoditionForOne(params, Activiter.ACTIVITER_MOBILE,Activiter.SIGN_CODE);
            String mobile = activiter.get(Activiter.ACTIVITER_MOBILE);			
            String signCode = activiter.get(Activiter.SIGN_CODE);			
		}
		renderText("短信发送成功");
	}
}
